package suncertify.db;

public class DataTest {

    static int recordVar = 0;
    /**
     * @param args
     */
    public static void main(String[] args) {
        final Data data = new Data("Test");
            Runnable r = new Runnable(){
                public void run(){
                    try{
                        System.out.println("Id = "+ Thread.currentThread().getId());
                        long threadId = data.lock(3);
                        long threadIdVar = data.lock(recordVar);
                        System.out.println("Has already Locked recNo 3 id = " + threadId);
                        System.out.println("Has already Locked recordVar " + recordVar+ "id = " + threadId);
                        Thread.sleep(1000);
                        System.out.println("Unlocking recNo 3 id = " + threadId);
                        System.out.println("Unlocking recordVar = " + recordVar+" id = " + threadId);
                        data.unlock(3, threadId);
                        data.unlock(recordVar, threadId);
                    }catch(DatabaseException exception){
                        System.out.println("Exception 1");
                    }catch (InterruptedException exception){
                        System.out.println("Exception 2");
                    }
                }
            };
        for (int i=0; i<20; i++){
            recordVar++;
            new Thread(r).start();
        }
    }

}
